package com.yike.user.controller;

import com.yike.user.entity.UserConsult;
import com.yike.user.param.UpdateConsultStatus;
import com.yike.user.param.UserConsultParam;
import com.yike.user.service.UserConsultService;
import com.yike.user.vo.UserConsultVo;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.UserConsultPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.api.IdParam;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户咨询 控制器
 *
 * @author Sakura
 * @since 2025-04-25
 */
@Slf4j
@RestController
@RequestMapping("/userConsult")
@Module("user")
@Api(value = "用户咨询API", tags = {"用户咨询"})
public class UserConsultController extends BaseController {

    @Autowired
    private UserConsultService userConsultService;

    /**
     * 添加用户咨询
     */
    @PostMapping("/add")
    @OperationLog(name = "添加用户咨询", type = OperationLogType.ADD)
    @ApiOperation(value = "添加用户咨询", response = ApiResult.class)
    public ApiResult<Boolean> addUserConsult(@Validated(Add.class) @RequestBody UserConsultParam userConsultParam) throws Exception {
        boolean flag = userConsultService.saveUserConsult(userConsultParam);
        return ApiResult.result(flag);
    }

    /**
     * 修改用户咨询
     */
//    @PostMapping("/update")
//    @OperationLog(name = "修改用户咨询", type = OperationLogType.UPDATE)
//    @ApiOperation(value = "修改用户咨询", response = ApiResult.class)
//    public ApiResult<Boolean> updateUserConsult(@Validated(Update.class) @RequestBody UserConsult userConsult) throws Exception {
//        boolean flag = userConsultService.updateUserConsult(userConsult);
//        return ApiResult.result(flag);
//    }

    /**
     * 删除用户咨询
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除用户咨询", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除用户咨询", response = ApiResult.class)
    public ApiResult<Boolean> deleteUserConsult(@PathVariable("id") Long id) throws Exception {
        boolean flag = userConsultService.deleteUserConsult(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取用户咨询详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "用户咨询详情", type = OperationLogType.INFO)
    @ApiOperation(value = "用户咨询详情", response = UserConsultVo.class)
    public ApiResult<UserConsultVo> getUserConsult(@PathVariable("id") Long id) throws Exception {
        UserConsultVo info = userConsultService.getUserConsult(id);
        return ApiResult.ok(info);
    }

    /**
     * 用户咨询分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "用户咨询分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "用户咨询分页列表", response = UserConsultVo.class)
    public ApiResult<Paging<UserConsultVo>> getUserConsultPageList(@Validated @RequestBody UserConsultPageParam userConsultPageParam) throws Exception {
        Paging<UserConsultVo> paging = userConsultService.getUserConsultPageList(userConsultPageParam);
        return ApiResult.ok(paging);
    }

    @PostMapping("/updateStatus")
    @OperationLog(name = "修改咨询状态", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改咨询状态", response = ApiResult.class)
    public ApiResult<Boolean> updateStatus(@Validated(Update.class) @RequestBody UpdateConsultStatus updateConsultStatus) throws Exception {
        boolean flag = userConsultService.updateStatus(updateConsultStatus);
        return ApiResult.result(flag);
    }

    @GetMapping("/getUnreadNum")
    @OperationLog(name = "获取未读数量", type = OperationLogType.INFO)
    @ApiOperation(value = "获取未读数量", response = ApiResult.class)
    public ApiResult<Integer> getUnreadNum() throws Exception {
        Integer num = userConsultService.getUnreadNum();
        return ApiResult.ok(num);
    }

}

